package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.OaTaxRate;
import com.ruoyi.system.service.IOaTaxRateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 汇率Controller
 *
 * @author ruoyi
 * @date 2025-03-13
 */
@RestController
@RequestMapping("/system/rate")
@Transactional
public class OaTaxRateController extends BaseController
{
    @Autowired
    private IOaTaxRateService oaTaxRateService;

    /**
     * 查询汇率列表
     */
    @PreAuthorize("@ss.hasPermi('system:rate:list')")
    @GetMapping("/list")
    public TableDataInfo list(OaTaxRate oaTaxRate)
    {
        startPage();
        List<OaTaxRate> list = oaTaxRateService.selectOaTaxRateList(oaTaxRate);
        return getDataTable(list);
    }

    /**
     * 导出汇率列表
     */
    @PreAuthorize("@ss.hasPermi('system:rate:export')")
    @Log(title = "汇率", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OaTaxRate oaTaxRate)
    {
        List<OaTaxRate> list = oaTaxRateService.selectOaTaxRateList(oaTaxRate);
        ExcelUtil<OaTaxRate> util = new ExcelUtil<OaTaxRate>(OaTaxRate.class);
        util.exportExcel(response, list, "汇率数据");
    }

    /**
     * 获取汇率详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(oaTaxRateService.selectOaTaxRateById(id));
    }

    /**
     * 新增汇率
     */
    @PreAuthorize("@ss.hasPermi('system:rate:add')")
    @Log(title = "汇率", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OaTaxRate oaTaxRate)
    {
        return toAjax(oaTaxRateService.insertOaTaxRate(oaTaxRate));
    }

    /**
     * 修改汇率
     */
    @PreAuthorize("@ss.hasPermi('system:rate:edit')")
    @Log(title = "汇率", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OaTaxRate oaTaxRate)
    {
        return toAjax(oaTaxRateService.updateOaTaxRate(oaTaxRate));
    }

    /**
     * 删除汇率
     */
    @PreAuthorize("@ss.hasPermi('system:rate:remove')")
    @Log(title = "汇率", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(oaTaxRateService.deleteOaTaxRateByIds(ids));
    }
}
